package com.party.core.service.photo.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.photo.PhotosMemberOperateReadDao;
import com.party.core.dao.write.photo.PhotosMemberOperateWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.photo.PhotosMemberOperate;
import com.party.core.model.photo.PhotosRankOutput;
import com.party.core.service.photo.IPhotosMemberOperateService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/5/30 14:28
 */
@Service
public class PhotosMemberOperateService implements IPhotosMemberOperateService {

    @Autowired
    private PhotosMemberOperateReadDao photosMemberOperateReadDao;

    @Autowired
    private PhotosMemberOperateWriteDao photosMemberOperateWriteDao;

    @Override
    public String insert(PhotosMemberOperate photosMemberOperate) {
        BaseModel.preInsert(photosMemberOperate);
        boolean result = photosMemberOperateWriteDao.insert(photosMemberOperate);
        if (result){
            return photosMemberOperate.getId();
        }
        return null;
    }

    @Override
    public boolean update(PhotosMemberOperate photosMemberOperate) {
        return photosMemberOperateWriteDao.update(photosMemberOperate);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return photosMemberOperateWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return photosMemberOperateWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return photosMemberOperateWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return photosMemberOperateWriteDao.batchDelete(ids);
    }

    @Override
    public PhotosMemberOperate get(String id) {
        return photosMemberOperateReadDao.get(id);
    }

    @Override
    public List<PhotosMemberOperate> listPage(PhotosMemberOperate photosMemberOperate, Page page) {
        return photosMemberOperateReadDao.listPage(photosMemberOperate, page);
    }

    @Override
    public List<PhotosMemberOperate> list(PhotosMemberOperate photosMemberOperate) {
        return listPage(photosMemberOperate, null);
    }

    @Override
    public List<PhotosMemberOperate> batchList(Set<String> ids, PhotosMemberOperate photosMemberOperate, Page page) {
        return null;
    }

    @Override
    public List<PhotosRankOutput> rankPage(PhotosMemberOperate photosMemberOperate, Page page) {
        return photosMemberOperateReadDao.rankPage(photosMemberOperate, page);
    }

    @Override
    public List<PhotosMemberOperate> findByPhotoId(String photoId) {
        PhotosMemberOperate memberOperate = new PhotosMemberOperate();
        memberOperate.setPhotosId(photoId);
        return photosMemberOperateReadDao.listPage(memberOperate, null);
    }

    @Override
    public void deleteByPhotoId(String photoId) {
        photosMemberOperateWriteDao.deleteByPhotoId(photoId);
    }
}
